package br.com.vti.sisp_sicrim.antigo.controller.relatorios;

import java.io.FileNotFoundException;
import java.text.ParseException;
import java.util.Arrays;

import net.sf.jasperreports.engine.JRException;
import br.com.caelum.vraptor.Result;
import br.com.vti.sisp_sicrim.antigo.model.DidCadastro;
import br.com.vti.sisp_sicrim.antigo.model.DidEmissao;
import br.com.vti.sisp_sicrim.antigo.model.Estla001;
import br.com.vti.sisp_sicrim.antigo.model.SicCadastro;
import br.com.vti.sisp_sicrim.antigo.model.SicCadnovo;
import br.com.vti.sisp_sicrim.antigo.model.SicControle;
import br.com.vti.sisp_sicrim.antigo.model.SicEstatistica;
import br.com.vti.sisp_sicrim.antigo.model.SicSenha;
import br.com.vti.sisp_sicrim.antigo.model.SicTabelas;
import br.com.vti.sisp_sicrim.antigo.model.Sislac01;
import br.com.vti.sisp_sicrim.antigo.util.Relatorios;
import br.com.vti.sisp_sicrim.antigo.util.Sessao;
import br.com.vti.sisp_sicrim.antigo.util.UtilBean;

/**
 * Classe responsavel por encapsular o tratamento e as consistencias da tela Scrppa02Report
 * 
 * @author Incode - Data: mai/2014
 * 
 */
public class Scrppa02Report {
	private long jRegger;
	private String nomeClasse;
	private String jDadNumPassaporte;
	private String jDadPaisOrigem;
	private String wNumReg;
	private String f1;
	private String f2;
	private String fx;
	private int datnas;
	private String dataprint;
	private String novoTipoReg; // DB
	private Long novoRegger; // DB
	public String filia1;
	public String f3;
	private String[] nomide = new String[3];
	private String horaCorrente;
	private Result result;
	private Sessao sessao;
	private Relatorios report;
	// Classes views
	SicSenha senhaView = new SicSenha();
	DidCadastro vwDidcad = new DidCadastro();
	DidEmissao vwEmissao = new DidEmissao();
	SicCadastro criminalView = new SicCadastro();
	SicCadnovo sicCadnovoView = new SicCadnovo();
	SicTabelas vwTabele = new SicTabelas();
	SicControle vwDvecon = new SicControle();
	SicTabelas vwDvetab = new SicTabelas();
	SicEstatistica vwCadest = new SicEstatistica();
	// Classes includes
	Estla001 estla001 = new Estla001();
	Sislac01 sislac01 = new Sislac01();

	public Scrppa02Report() throws JRException {
		inicializar();
	}

	public Scrppa02Report(Sessao sessao) throws JRException {
		this.sessao = sessao;
		inicializar();
	}

	public void inicializar() throws JRException {
		report = new Relatorios();
		jRegger = 0;
		nomeClasse = this.getClass().getSimpleName();
		jDadNumPassaporte = "";
		jDadPaisOrigem = "";
		wNumReg = "";
		Arrays.fill(nomide, "");
		fx = "";
		datnas = 0;
		dataprint = "";
		report.setNumeroRel(1, "D");
		{
			report.setNumeroLinhaRel(3, 1);
			{
				report.adicionaCampo(50, 22, "Wnumreg", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(9, 1);
			{
				report.adicionaCampo(3, 60, "Nomide[1]", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(11, 2);
			{
				report.adicionaCampo(3, 9, "lit_3_9", "C", "", "FILIACAO:");
				report.adicionaCampo(13, 60, "Fx", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(12, 1);
			{
				report.adicionaCampo(13, 60, "F2", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(14, 2);
			{
				report.adicionaCampo(3, 10, "lit_3_10", "C", "", "NASCIDO A:");
				report.adicionaCampo(14, 8, "Datnas", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(21, 1);
			{
				report.adicionaCampo(12, 10, "Dataprint", "X", "", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(2, "D");
		{
			report.setNumeroLinhaRel(3, 1);
			{
				report.adicionaCampo(50, 22, "Wnumreg", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(9, 1);
			{
				report.adicionaCampo(3, 60, "Nomide[1]", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(11, 2);
			{
				report.adicionaCampo(3, 9, "lit_3_9", "C", "", "FILIACAO:");
				report.adicionaCampo(13, 60, "Fx", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(12, 1);
			{
				report.adicionaCampo(13, 60, "F2", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(14, 2);
			{
				report.adicionaCampo(3, 10, "lit_3_10", "C", "", "NASCIDO A:");
				report.adicionaCampo(14, 8, "Datnas", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(21, 1);
			{
				report.adicionaCampo(12, 10, "Dataprint", "X", "", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(3, "D");
		{
			report.setNumeroLinhaRel(2, 2);
			{
				report.adicionaCampo(50, 10, "lit_50_10", "C", "", "PASSAPORT-");
				report.adicionaCampo(61, 13, "Jdadnumpassaporte", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(3, 1);
			{
				report.adicionaCampo(50, 20, "Jdadpaisorigem", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(8, 1);
			{
				report.adicionaCampo(3, 60, "Nomide[1]", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(10, 3);
			{
				report.adicionaCampo(3, 9, "lit_3_9", "C", "", "FILIACAO:");
				report.adicionaCampo(13, 58, "F1", "X", "", "");
				report.adicionaCampo(72, 2, "lit_72_2", "C", "", " E");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(11, 1);
			{
				report.adicionaCampo(13, 60, "F2", "X", "", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(13, 2);
			{
				report.adicionaCampo(3, 10, "lit_3_10", "C", "", "NASCIDO A:");
				report.adicionaCampo(14, 8, "Datnas", "N", "99/99/9999", "");
				report.setFimLinhaRel();
			}
			report.setNumeroLinhaRel(21, 1);
			{
				report.adicionaCampo(12, 10, "Dataprint", "X", "", "");
				report.setFimLinhaRel();
			}
		}
		report.setNumeroRel(4, "D");
		{
			report.setNumeroLinhaRel(1, 2);
			{
				report.adicionaCampo(1, 2, "Novotiporeg", "X", "", "");
				report.adicionaCampo(4, 13, "Novoregger", "N", "", "");
				report.setFimLinhaRel();
			}
		}
	}

	public boolean validar() {
		return true;
	}

	public long getJregger() {
		return jRegger;
	}

	public void setJregger(long jRegger) throws ParseException {
		this.jRegger = jRegger;
		report.adicionaValorReport("Jregger", jRegger);
	}

	public String getNomeClasse() {
		return nomeClasse;
	}

	public void setNomeClasse(String nomeClasse) throws ParseException {
		this.nomeClasse = nomeClasse;
		report.adicionaValorReport("Program", nomeClasse);
	}

	public String getJdadnumpassaporte() {
		return jDadNumPassaporte;
	}

	public void setJdadnumpassaporte(String jDadNumPassaporte) throws ParseException {
		this.jDadNumPassaporte = jDadNumPassaporte;
		report.adicionaValorReport("Jdadnumpassaporte", jDadNumPassaporte);
	}

	public String getJdadpaisorigem() {
		return jDadPaisOrigem;
	}

	public void setJdadpaisorigem(String jDadPaisOrigem) throws ParseException {
		this.jDadPaisOrigem = jDadPaisOrigem;
		report.adicionaValorReport("Jdadpaisorigem", jDadPaisOrigem);
	}

	public String getWnumreg() {
		return wNumReg;
	}

	public void setWnumreg(String wNumReg) throws ParseException {
		this.wNumReg = wNumReg;
		report.adicionaValorReport("Wnumreg", wNumReg);
	}

	public String getF1() {
		return f1;
	}

	public void setF1(String f1) throws ParseException {
		this.f1 = f1;
		report.adicionaValorReport("F1", f1);
	}

	public String getF2() {
		return f2;
	}

	public void setF2(String f2) throws ParseException {
		this.f2 = f2;
		report.adicionaValorReport("F2", f2);
	}

	public String getFx() {
		return fx;
	}

	public void setFx(String fx) throws ParseException {
		this.fx = fx;
		report.adicionaValorReport("Fx", fx);
	}

	public int getDatnas() {
		return datnas;
	}

	public void setDatnas(int datnas) throws ParseException {
		this.datnas = datnas;
		report.adicionaValorReport("Datnas", datnas);
	}

	public String getDataprint() {
		return dataprint;
	}

	public void setDataprint(String dataprint) throws ParseException {
		this.dataprint = dataprint;
		report.adicionaValorReport("Dataprint", dataprint);
	}

	public String[] getNomide() {
		return nomide;
	}

	public void setNomide(String[] nomide) throws ParseException {
		this.nomide = nomide;
		report.adicionaValorReport("Nomide", nomide);
	}

	public String getNomide(int index) {
		return nomide[index];
	}

	public void setNomide(int index, String nomide) throws ParseException {
		this.nomide[index] = nomide;
		report.adicionaValorReport("Nomide" + "[" + String.valueOf(index) + "]", nomide);
	} // /

	public String getFilia1() {
		return this.f1 + this.f2 + this.f3;
	}

	public void setFilia1(String filia1) throws ParseException {
		this.filia1 = filia1;
		this.f1 = UtilBean.subStr(filia1, 0, 58);
		report.adicionaValorReport("F1", UtilBean.subStr(filia1, 0, 58));
		this.f2 = UtilBean.subStr(filia1, 58, 60);
		report.adicionaValorReport("F2", UtilBean.subStr(filia1, 58, 60));
		this.f3 = UtilBean.subStr(filia1, 118, 3);
		report.adicionaValorReport("F3", UtilBean.subStr(filia1, 118, 3));
	}

	public void setPageSize(int pagesize) throws JRException {
		report.setPageSize(pagesize);
	}

	public void setLineSize(int linesize) {
		report.setLineSize(linesize);
	}

	public int getPageSize() {
		return report.getPageSize();
	}

	public int getPageLine() {
		return report.getPageLine();
	}

	public void saltaLinhas(int qtdLinhas) throws ParseException, JRException {
		report.saltaLinhas(qtdLinhas);
	}

	public void gravaRelatorio(int nroRel) throws ParseException, JRException {
		report.gravaRelatorio(report, nroRel, false);
	}

	public void imprimir() throws FileNotFoundException, JRException {
		report.imprimir();
	}
}
